home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / M2Crypto / m2urllib2.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  3KB  |  93 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. from urllib2 import *
  5. import urlparse
  6. import SSL
  7. import httpslib
  8.  
  9. class HTTPSHandler(AbstractHTTPHandler):
  10.     
  11.     def __init__(self, ssl_context = None):
  12.         AbstractHTTPHandler.__init__(self)
  13.         if ssl_context is not None:
  14.             self.ctx = ssl_context
  15.         else:
  16.             self.ctx = SSL.Context()
  17.  
  18.     
  19.     def https_open(self, req):
  20.         host = req.get_host()
  21.         if not host:
  22.             raise URLError('no host given')
  23.         
  24.         full_url = req.get_full_url()
  25.         target_host = urlparse.urlparse(full_url)[1]
  26.         if target_host != host:
  27.             h = httpslib.ProxyHTTPSConnection(host = host, ssl_context = self.ctx)
  28.         else:
  29.             h = httpslib.HTTPSConnection(host = host, ssl_context = self.ctx)
  30.         h.set_debuglevel(self._debuglevel)
  31.         headers = dict(req.headers)
  32.         headers.update(req.unredirected_hdrs)
  33.         headers['Connection'] = 'close'
  34.         
  35.         try:
  36.             h.request(req.get_method(), req.get_full_url(), req.data, headers)
  37.             r = h.getresponse()
  38.         except socket.error:
  39.             err = None
  40.             raise URLError(err)
  41.  
  42.         r.recv = r.read
  43.         fp = socket._fileobject(r)
  44.         resp = addinfourl(fp, r.msg, req.get_full_url())
  45.         resp.code = r.status
  46.         resp.msg = r.reason
  47.         return resp
  48.  
  49.     https_request = AbstractHTTPHandler.do_request_
  50.  
  51.  
  52. def build_opener(ssl_context = None, *handlers):
  53.     opener = OpenerDirector()
  54.     default_classes = [
  55.         ProxyHandler,
  56.         UnknownHandler,
  57.         HTTPHandler,
  58.         HTTPDefaultErrorHandler,
  59.         HTTPRedirectHandler,
  60.         FTPHandler,
  61.         FileHandler,
  62.         HTTPErrorProcessor]
  63.     skip = []
  64.     for klass in default_classes:
  65.         for check in handlers:
  66.             if inspect.isclass(check):
  67.                 if issubclass(check, klass):
  68.                     skip.append(klass)
  69.                 
  70.             issubclass(check, klass)
  71.             if isinstance(check, klass):
  72.                 skip.append(klass)
  73.                 continue
  74.         
  75.     
  76.     for klass in skip:
  77.         default_classes.remove(klass)
  78.     
  79.     for klass in default_classes:
  80.         opener.add_handler(klass())
  81.     
  82.     if HTTPSHandler not in skip:
  83.         opener.add_handler(HTTPSHandler(ssl_context))
  84.     
  85.     for h in handlers:
  86.         if inspect.isclass(h):
  87.             h = h()
  88.         
  89.         opener.add_handler(h)
  90.     
  91.     return opener
  92.  
  93.